package com.custom.base.dialog

import android.view.View
import android.widget.TextView
import com.custom.base.R
import com.custom.base.util.SDViewUtil

/**
 * 作者：
 * 时间：2021/1/14
 * 描述：下载
 */
class DialogDownload(content:String,forceUpdate:Boolean = false,listener:OnDownloadListener? = null) :SDDialogBase(){

    init {
        val mView = SDViewUtil.getRId(context, R.layout.dialog_dowlon)
        val contentTv = mView.findViewById<TextView>(R.id.dialog_dowlon_content)
        val cancel = mView.findViewById<TextView>(R.id.dialog_dowloan_cancel)
        val confirm = mView.findViewById<TextView>(R.id.dialog_dowloan_confirm)
        val progress = mView.findViewById<com.custom.base.view.HorizontalProgressBar>(R.id.dialog_dowlon_progress)

        contentTv.text = content
        if(forceUpdate) {
            cancel.visibility = View.GONE
        }
        confirm.setOnClickListener {
            progress.visibility = View.VISIBLE
            cancel.text = "后台更新"
            listener?.onConfirm(this,progress,confirm,forceUpdate)
        }
        cancel.setOnClickListener {
            dismissClick()
        }

        setDialogView(mView)

        setCancelable(false)
    }

    interface OnDownloadListener{
        fun onConfirm(
            dialog: DialogDownload,
            progressBar: com.custom.base.view.HorizontalProgressBar,
            confirm: TextView,
            force: Boolean
        )
    }
}